-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
[material-ui][Chip] Add slots and slotProps #46098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Netlify deploy previewhttps://deploy-preview-46098--material-ui.netlify.app/ @mui/material/Chip: parsed: +2.15% , gzip: +2.04% Bundle size reportDetails of bundle changes (Toolpad) |
}, | ||
ownerState, | ||
ref: handleRef, | ||
shouldForwardComponentProp: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldForwardComponentProp: true, |
ChipRoot comes from div
, no need to forward component prop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The component
prop was forwarded because, when shouldForwardComponentProp
is set to false
, the component
prop returned from useSlot('root')
gets removed in the useSlot.ts
file and replaced with the as
prop here.
While this behavior works fine for components that do not rely on component
-specific logic, it breaks components like Chip
, which access the component
prop directly in their logic — for example, this line. Removing the component
prop in such cases causes test failures.
To fix this, I added shouldForwardComponentProp: true
to ensure that the component
prop is preserved and Chip
continues to behave correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Can you add a comment above the line shouldForwardComponentProp
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, added here 29b9ea4
@sai6855 Can you check the CIs? Some are failing. |
label: { | ||
expectedClassName: classes.label, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the comment about the shouldForwardComponentProp
. I think we need to add more tests.
- With
clickable: true
and a customcomponent
prop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
material-ui/packages/mui-material/src/Chip/Chip.test.js
Lines 83 to 88 in 4cfd2f7
it('should render link with the button base', () => { | |
const { container } = render(<Chip component="a" clickable label="My text Chip" />); | |
expect(container.firstChild).to.have.class('MuiButtonBase-root'); | |
expect(container.firstChild).to.have.tagName('a'); | |
}); |
This PR adds slots and slotProps to Chip component